﻿
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Imports System.Data.OleDb.OleDbConnection
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports System.IO


Public Class ActivJob

    Public Ref As String


    Private dataAdapter As New MySqlDataAdapter

    Private Sub ActivJob_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            GridView1.SaveLayoutToXml(My.Settings.ConfigPath & "\ActivJobGW01.xml")
        Catch ex As Exception
        End Try

        My.Settings.ActivJobPos = Me.Location
        My.Settings.ActivJobSize = Me.Size


    End Sub

    Private Sub ActivJob_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Me.Location = My.Settings.ActivJobPos
        Me.Size = My.Settings.ActivJobSize


        Me.Cursor() = Cursors.WaitCursor



        GetData("SELECT  Count(*) as '# of doors', from_unixtime(ValDatBodGeplanterabschlus2927/1000) AS Abschluss, ValDatBodExterneauftragsnud106 as Auftragsnummer, " & _
                " ValDatBodEinsatznummerccf5 as Einsatznummer, ValAblStatusb22e as Status, ValAblTecMandanted4 as Land, ValAblTecName60ff as Tchniker," & _
                "ValAblTecTechnikeridfc40 as 'Techniker ID', ValDatBodAuftragsartede4 as Auftragstyp , " & _
                "ValDatKunAdrName7979 as Kunde, ValDatKunAdrAdresszeile1d867 as Addr1 ,ValDatKunAdrAdresszeile2d864 as Addr2, ValDatKunAdrAdresszeile3d865 as Addr3, ValDatKunAdrAdresszeile4d862 as Addr4, " & _
                "ValDatKunAdrPlz6b42 as PLZ,ValDatKunAdrOrt9692 as Ort, " & _
                "ValDatBodStoerungsbeschreicf2b as Description, " & _
                "ValDatObjGeoBreitengraddaa3 as Latitude, ValDatObjGeoLaengengrad7edc as Longitude " & _
                "FROM auftragrow JOIN auftragrowvaldatobjtuerene261  ON auftragrow.Kee = auftragrowvaldatobjtuerene261.FkKee " & _
                "WHERE ValAblStatusb22e in ('400','500', '600', '610', '700') AND ValAblTecMandanted4 = 'CH' AND ValDatBodGeplanterabschlus2927 >= '1262453880000' AND ValAblTecTechnikeridfc40 Like '%" & OpenMap.ActivTech & "%' " & _
                "Group by ValDatBodExterneauftragsnud106 " & _
                "order by ValAblStatusb22e desc")

        Me.Cursor() = Cursors.Default
    End Sub

    Function GetData(ByVal selectCommand As String)

        Try
            Dim ConCM As MySqlConnection
            ConCM = New MySqlConnection(My.Settings.MySQL)
            ConCM.Open()

            Dim cmd As New MySqlCommand(selectCommand, ConCM)

            Me.dataAdapter = New MySqlDataAdapter(cmd)
            Dim table As New DataTable
            table.Locale = System.Globalization.CultureInfo.InvariantCulture
            Me.dataAdapter.Fill(table)
            Me.BindingSource1.DataSource = table

            ' Resize the DataGridView columns to fit the newly loaded content.
            'Me.DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
            GridView1.BestFitColumns()
            If File.Exists(My.Settings.ConfigPath & "\ActivJobGW01.xml") Then GridView1.RestoreLayoutFromXml(My.Settings.ConfigPath & "\ActivJobGW01.xml")


            ConCM.Close()

            Me.BarStaticItem1.Caption = "JLD004 / ActivJob : " & GridView1.RowCount.ToString


        Catch ex As OleDbException

        End Try
        GetData = ""

    End Function







End Class